package com.lottery.common.service.Impl;

import com.lottery.common.aop.Action;
import com.lottery.common.service.DecryptToObjectService;
import com.lottery.common.utils.ConnectionUrlUtil;
import com.lottery.common.utils.RSAUtils;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

@Service
public class DecryptToObjectServiceImpl implements DecryptToObjectService {


    @Override
    @Action(name="api")
    public <T> T decryptApiToObject(String data, Class<T> pojoCalss) throws Exception {
        return RSAUtils.decryptToObject2(data,pojoCalss);
    }

    @Override
    @Action(name="web")
    public <T> T decryptWebToObject(String data, Class<T> pojoCalss) throws Exception {
        return RSAUtils.decryptToObject(data,pojoCalss);
    }

    @Override
    @Action(name="jsonStr")
    public <T> T webJsonStrToObject(String data, Class<T> pojoCalss) throws Exception {
        return RSAUtils.jsonToObject(data, pojoCalss);
    }

    @Override
    public <T> T webBaseToObject(String data, Class<T> pojoCalss) throws Exception {
        return null;
    }

    @Override
    public String decryptApiToString(String data) throws Exception {
        return null;
    }

    @Override
    public <T> T jsonToObject(String data, Class<T> pojoCalss)  {
        return RSAUtils.jsonToObject(data,pojoCalss);
    }

    @Override
    @Action(name="request")
    public <T> T requestToObject(HttpServletRequest request, Class<T> pojoCalss) throws Exception {
        return RSAUtils.jsonToObject(ConnectionUrlUtil.getParams(request),pojoCalss) ;
    }

    @Override
    @Action(name="dRequest")
    public <T> T decryptRequestToObject(HttpServletRequest request, Class<T> pojoCalss) throws Exception {
        return RSAUtils.decryptToObject2(ConnectionUrlUtil.getParams(request),pojoCalss);
    }

    @Override
    public String decryptWebToString(String data) throws Exception {
        return RSAUtils.rsaDecryptCipher(data);
    }
}
